package logic

import (
	"context"
	"gorm.io/gorm"
	"house/models/mysql"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppListLogic {
	return &AppListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AppListLogic) AppList(in *houserpc.AppListRequest) (*houserpc.AppListResponse, error) {
	// todo: add your logic here and delete this line

	var app mysql.App
	mysql.DB.Debug().Where("AppName", in.AppId).Find(&app)

	apps := mysql.House{
		Model: gorm.Model{ID: app.ID},
	}
	mysql.DB.Debug().Find(&apps)

	return &houserpc.AppListResponse{
		AppName: app.AppName,
		UserId:  int64(app.UserId),
		HouseId: int64(app.HouseId),
	}, nil
}
